#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Maxn=2e6+7;
int buf[Maxn];

int n;
vector<int>e[Maxn];
int mxdep[Maxn],dep[Maxn],len[Maxn],son[Maxn];

int ans[Maxn];
int *f[Maxn],*now=buf;

void dfs(int u,int ft){
    dep[u]=dep[ft]+1;
    mxdep[u]=dep[u];
    for(auto v:e[u]){
        if(v==ft) continue;
        dfs(v,u);
        if(mxdep[v]>mxdep[u]) mxdep[u]=mxdep[v];
        if(mxdep[v]>mxdep[son[u]]) son[u]=v;
    }
}
void dfs2(int u,int ft){
    f[u][0]=1;
    if(son[u]){
        dfs2(son[u],u);
        f[u]=f[son[u]]+1;
        ans[u]=ans[son[u]]+1;
    }
    for(auto v:e[u]){
        if(v==son[u] or v==ft) continue;
        f[v]=now,now+=dep[v];
        dfs2(v,u);
        for(int i=1;i<=dep[v];i++){
            f[u][i]+=f[v][i-1];
            if(f[u][i]>f[u][ans[u]]) ans[u]=i;
            else if(f[u][i]==f[u][ans[u]]) ans[u]=min(ans[u],i);
        }
    }
}

int main(){
    freopen("talk.in","r",stdin);
    freopen("talk.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }

    dfs(1,0);
    f[1]=now,now+=dep[1];
    dfs2(1,0);

    printf("%d\n",ans[1]);

    system("pause");
    return 0;
}